package main

import (
	"os"
	"os/signal"
	"syscall"

	"github.com/hanwen/go-fuse/v2/fs"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

func main() {
	config, err := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
	checkErr(err)
	clientset, err := kubernetes.NewForConfig(config)
	checkErr(err)

	// 设置 Kubernetes 命名空间、Pod 名称和容器名称
	namespace := "default"
	podName := "busybox-test-7986dc67b4-7jq8k"
	container := "busybox"

	// 创建 FUSE 文件系统
	root := NewKubernetesFS(clientset, config, namespace, podName, container)
	ops := &fs.Options{}
	ops.Debug = true
	server, err := fs.Mount("tmp", root, ops)
	checkErr(err)
	defer server.Unmount()

	sigCh := make(chan os.Signal, 1)
	signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
	<-sigCh
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}
